package java8Test.function;

import java.util.function.*;

/**
 * @author : yang.xp
 * @date : 2022/5/7 10:36
 * @description : Consumer
 */
public class FunctionTest<T extends ObjectObj, U extends ObjectObj> {

    public static final Consumer<ObjectObj> consumer = ObjectObj::eat;
    public static final BiConsumer<ObjectObj, ObjectObj> biconsumer = (t, u) -> {
        t.eat();
        u.eat();
    };

    public static final Predicate<ObjectObj> predicate1 = t1 -> t1.getNum() == 1;
    public static final Predicate<ObjectObj> predicate2 = ObjectObj::isHero;

    // 两个参数的Function
    public static final StrategyExpression<ObjectObj, ObjectObj> sameNumFunc = a -> b -> a.getNum() == b.getNum();
    public static final ThreeParamFunction<ObjectObj, ObjectObj, ObjectObj> sameNumFunc2 = (a, b) -> c -> a.getNum() == b.getNum() && b.getNum() == c.getNum();
    public static final ThreeParamFunction2<ObjectObj, ObjectObj, ObjectObj> sameNumFunc3 = a -> (b, c) -> a.getNum() == b.getNum() && b.getNum() == c.getNum();

    public static void main(String[] args) {

        FunctionTest functionTest = new FunctionTest();
        functionTest.consumer1(new ObjectObj(), consumer);

        // 比较器
        ObjectObj objectObj1 = new ObjectObj();
        objectObj1.setNum(1);
        System.out.println(predicate1.test(objectObj1));

        ObjectObj objectObj2 = new ObjectObj();
        objectObj2.setNum(2);
        System.out.println(sameNumFunc.run(objectObj1).test(objectObj2));

        ObjectObj objectObj3 = new ObjectObj();
        objectObj3.setNum(1);

        // Function
        System.out.println(sameNumFunc2.run(objectObj1, objectObj2).ppcffg(objectObj3));
        System.out.println(sameNumFunc3.fccs2(objectObj1).ppcffg(objectObj2, objectObj3));

        // supplier
        functionTest.supplier(objectObj1, () -> objectObj2);

        // unaryOperator
        functionTest.unaryOperator(objectObj1);

        // BiConsumer
        functionTest.consumer2(objectObj1, objectObj2, biconsumer);
        // BiPredicate
        // BiFunction
        // BinaryOperator
    }

    public void consumer1(T param1, Consumer<T> consumer) {
        consumer.accept(param1);
    }

    public void consumer2(T param1, U param2, BiConsumer<T, U> biConsumer) {
        biConsumer.accept(param1, param2);
    }

    public void supplier(T param1, Supplier<T> supplier) {
        T t = supplier.get();
        System.out.println(t.getNum() == param1.getNum());
    }

    public ObjectObj unaryOperator(T param1) {
        return (ObjectObj) UnaryOperator.identity().apply(param1);
    }
}